package com.ruoyi.fee.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fee.domain.WCustomerSettlementMode;
import com.ruoyi.fee.service.IWCustomerSettlementModeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户结算方式Controller
 * 
 * @author wzy
 * @date 2024-08-30 14:32:52
 */
@RestController
@RequestMapping("/fees/mode")
public class WCustomerSettlementModeController extends BaseController
{
    @Autowired
    private IWCustomerSettlementModeService wCustomerSettlementModeService;

    /**
     * 查询客户结算方式列表
     */
    @PreAuthorize("@ss.hasPermi('fees:mode:list')")
    @GetMapping("/list")
    public TableDataInfo list(WCustomerSettlementMode wCustomerSettlementMode)
    {
        startPage();
        List<WCustomerSettlementMode> list = wCustomerSettlementModeService.selectWCustomerSettlementModeList(wCustomerSettlementMode);
        return getDataTable(list);
    }

    /**
     * 导出客户结算方式列表
     */
    @PreAuthorize("@ss.hasPermi('fees:mode:export')")
    @Log(title = "客户结算方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WCustomerSettlementMode wCustomerSettlementMode)
    {
        List<WCustomerSettlementMode> list = wCustomerSettlementModeService.selectWCustomerSettlementModeList(wCustomerSettlementMode);
        ExcelUtil<WCustomerSettlementMode> util = new ExcelUtil<WCustomerSettlementMode>(WCustomerSettlementMode.class);
        util.exportExcel(response, list, "客户结算方式数据");
    }

    /**
     * 获取客户结算方式详细信息
     */
    @PreAuthorize("@ss.hasPermi('fees:mode:query')")
    @GetMapping(value = "/{customerSettlementModeId}")
    public AjaxResult getInfo(@PathVariable("customerSettlementModeId") Long customerSettlementModeId)
    {
        return success(wCustomerSettlementModeService.selectWCustomerSettlementModeByCustomerSettlementModeId(customerSettlementModeId));
    }

    /**
     * 新增客户结算方式
     */
    @PreAuthorize("@ss.hasPermi('fees:mode:add')")
    @Log(title = "客户结算方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WCustomerSettlementMode wCustomerSettlementMode)
    {
        wCustomerSettlementMode.setCreateBy(getNickName());
        return toAjax(wCustomerSettlementModeService.insertWCustomerSettlementMode(wCustomerSettlementMode));
    }

    /**
     * 修改客户结算方式
     */
    @PreAuthorize("@ss.hasPermi('fees:mode:edit')")
    @Log(title = "客户结算方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WCustomerSettlementMode wCustomerSettlementMode)
    {
        wCustomerSettlementMode.setUpdateBy(getNickName());
        return toAjax(wCustomerSettlementModeService.updateWCustomerSettlementMode(wCustomerSettlementMode));
    }

    /**
     * 删除客户结算方式
     */
    @PreAuthorize("@ss.hasPermi('fees:mode:remove')")
    @Log(title = "客户结算方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerSettlementModeIds}")
    public AjaxResult remove(@PathVariable Long[] customerSettlementModeIds)
    {
        return toAjax(wCustomerSettlementModeService.deleteWCustomerSettlementModeByCustomerSettlementModeIds(customerSettlementModeIds));
    }

    /**
     * 获取客户结算方式详细信息
     */
    //@PreAuthorize("@ss.hasPermi('fees:mode:query')")
    @GetMapping(value = "/custom/{customerName}")
    public AjaxResult getInfoByCustomerName(@PathVariable("customerName") String customerName)
    {
        return success(wCustomerSettlementModeService.selectWCustomerSettlementModeByCustomerName(customerName));
    }
}
